<template>
	<el-dialog :title="`权限设置`+(netDiskName!=''?'--【'+netDiskName+'】':'')" v-model="visible" :width="800" destroy-on-close @closed="$emit('closed')">
		<el-form :model="form" :rules="rules" :disabled="netDiskId==''" ref="dialogForm" label-width="100px" label-position="left">
			<el-tabs tab-position="top" type="card" @tab-change="tabChange">
				<el-tab-pane label="访问权限">
					<el-form :model="form" :rules="rules" ref="dialogForm" label-width="100px" label-position="left">
						<el-form-item label="人员权限" prop="accessUserRole">
							<select-user-dialog v-model:accountId="form.accessUserRole" :mode="true"/>
						</el-form-item>
						<el-form-item label="部门权限" prop="accessDeptRole">
							<select-dept-dialog v-model:deptId="form.accessDeptRole" :mode="true"/>
						</el-form-item>
						<el-form-item label="职务权限" prop="accessLevelRole">
							<select-user-level-dialog  v-model:levelId="form.accessLevelRole" :mode="true"/>
						</el-form-item>
					</el-form>
				</el-tab-pane>
				<el-tab-pane label="新建权限">
					<el-form label-width="100px" label-position="left">
						<el-form-item label="人员权限" prop="createUserRole">
							<select-user-dialog v-model:accountId="form.createUserRole" :mode="true"/>
						</el-form-item>
						<el-form-item label="部门权限" prop="createDeptRole">
							<select-dept-dialog v-model:deptId="form.createDeptRole" :mode="true"/>
						</el-form-item>
						<el-form-item label="职务权限" prop="createLevelRole">
							<select-user-level-dialog  v-model:levelId="form.createLevelRole" :mode="true"/>
						</el-form-item>
					</el-form>
				</el-tab-pane>
				<el-tab-pane label="下载权限">
					<el-form label-width="100px" label-position="left">
						<el-form-item label="人员权限" prop="downUserRole">
							<select-user-dialog v-model:accountId="form.downUserRole" :mode="true"/>
						</el-form-item>
						<el-form-item label="部门权限" prop="downUserRole">
							<select-dept-dialog v-model:deptId="form.createDeptRole" :mode="true"/>
						</el-form-item>
						<el-form-item label="职务权限" prop="downLevelRole">
							<select-user-level-dialog  v-model:levelId="form.downLevelRole" :mode="true"/>
						</el-form-item>
					</el-form>
				</el-tab-pane>
				<el-tab-pane label="管理权限">
					<el-form label-width="100px" label-position="left">
						<el-form-item label="人员权限" prop="manageUserRole">
							<select-user-dialog v-model:accountId="form.manageUserRole" :mode="true"/>
						</el-form-item>
						<el-form-item label="部门权限" prop="manageDeptRole">
							<select-dept-dialog v-model:deptId="form.manageDeptRole" :mode="true"/>
						</el-form-item>
						<el-form-item label="职务权限" prop="manageLevelRole">
							<select-user-level-dialog  v-model:levelId="form.manageLevelRole" :mode="true"/>
						</el-form-item>
					</el-form>
				</el-tab-pane>
				<el-tab-pane label="批量设置" name="batch">
					<el-form label-width="100px" label-position="left">
						<el-form-item label="人员权限" prop="userRole">
							<select-user-dialog v-model:accountId="batchform.userRole" :mode="true"/>
						</el-form-item>
						<el-form-item label="部门权限" prop="deptRole">
							<select-dept-dialog v-model:deptId="batchform.setBatchDeptRole" :mode="true"/>
						</el-form-item>
						<el-form-item label="职务权限" prop="levelRole">
							<select-user-level-dialog  v-model:levelId="batchform.levelRole" :mode="true"/>
						</el-form-item>
						<el-form-item label="选择范围" prop="range">
							<el-checkbox-group v-model="batchform.range">
								<el-checkbox-button label="1">访问权限</el-checkbox-button>
								<el-checkbox-button label="2">下载权限</el-checkbox-button>
								<el-checkbox-button label="3">管理权限</el-checkbox-button>
								<el-checkbox-button label="4">新建权限</el-checkbox-button>
							</el-checkbox-group>
						</el-form-item>
						<el-form-item label="操作方式" prop="optType">
							<el-radio-group v-model="batchform.optType">
								<el-radio-button label="1">添加权限</el-radio-button>
								<el-radio-button label="2">移除权限</el-radio-button>
							</el-radio-group>
						</el-form-item>
					</el-form>
				</el-tab-pane>
			</el-tabs>
			<div style="width: 100%;text-align: center;">
				<el-button type="primary" :loading="isSaveing" @click="batchSubmit()" v-if="tabName=='batch'">保 存</el-button>
				<el-button type="primary" :loading="isSaveing" @click="submit()" v-else>保 存</el-button>
			</div>
		</el-form>
	</el-dialog>
</template>
<script>
import selectUserDialog from "@/views/module/selectUserDialog";
import selectDeptDialog from "@/views/module/selectDeptDialog";
import selectUserLevelDialog from "@/views/module/selectUserLevelDialog";

export default {
	name: 'Net Disk Permission Setting',
	components: {
		selectUserLevelDialog,
		selectUserDialog,
		selectDeptDialog,
	},
	data() {
		return {
			visible: false,
			isSaveing: false,
			netDiskName: "",
			tabName: "",
			batchform: {
				netDiskId: '',
				userRole: '',
				deptRole: '',
				levelRole: '',
				optType: '1',
				range: []
			},
			form: {
				netDiskId: '',
				accessUserRole: '',
				accessDeptRole: '',
				accessLevelRole: '',
				createUserRole: '',
				createDeptRole: '',
				createLevelRole: '',
				downUserRole: '',
				downDeptRole: '',
				downLevelRole: '',
				manageUserRole: '',
				manageDeptRole: '',
				manageLevelRole: ''
			}
		}
	},
	methods: {
		tabChange(name) {
			this.tabName = name;
		},
		//显示
		open() {
			this.visible = true;
			return this;
		},
		submit() {
			this.$refs.dialogForm.validate(async (valid) => {
				if (valid) {
					this.isSaveing = true;
					var res = await this.$API.file.netDisk.update.post(this.form);
					this.isSaveing = false;
					if (res.code == 200) {
						this.$emit('success', this.form, this.mode)
						this.visible = false;
						this.$message.success("操作成功")
					} else {
						this.$alert(res.message, "提示", {type: 'error'})
					}
				}
			})
		},
		async batchSubmit() {
			var res;
			this.isSaveing = true;
			if (this.batchform.optType == "1") {
				res = await this.$API.file.netDisk.setNetDiskRole.post(this.batchform);
			} else if (this.batchform.optType == "2") {
				res = await this.$API.file.netDisk.removeNetDiskRole.post(this.batchform);
			}
			if (res.code == 200) {
				this.visible = false;
				this.$message.success("操作成功")
				this.$emit('success', this.form, this.mode)
			} else {
				this.$alert(res.message, "提示", {type: 'error'})
			}
		},
		setData(data) {
			this.netDiskName = data.netDiskName
			this.batchform.netDiskId = data.netDiskId;
			this.form.netDiskId = data.netDiskId
			this.form.accessUserRole = data.accessUserRole
			this.form.accessDeptRole = data.accessDeptRole
			this.form.accessLevelRole = data.accessLevelRole
			this.form.createUserRole = data.createUserRole
			this.form.createDeptRole = data.createDeptRole
			this.form.createLevelRole = data.createLevelRole
			this.form.downUserRole = data.downUserRole
			this.form.downDeptRole = data.downDeptRole
			this.form.downLevelRole = data.downLevelRole
			this.form.manageUserRole = data.manageUserRole
			this.form.manageDeptRole = data.manageDeptRole
			this.form.manageLevelRole = data.manageLevelRole

		}
	},
}

</script>
